package com.hub.service.impl;

import com.hub.dto.SearchUserModel;
import com.hub.mapper.UserMapper;
import com.hub.model.UserModel;
import com.hub.service.IUserService;
import com.hub.utils.ApiCodeEnum;
import com.hub.utils.ApiResultObject;
import com.hub.utils.enums.UserGenderEnum;
import com.hub.utils.enums.UserStatusEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements IUserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 
     * 登录
     * @param model
     * @return
     */
    @Override
    public ApiResultObject<UserModel> doLogin(SearchUserModel model){
        ApiResultObject resultObject = ApiResultObject.failed(ApiCodeEnum.FAILED.getCode(),"登录失败！");
        UserModel resultModel = userMapper.doUserLogin(model);
        if(null != resultModel){
            //性别
            resultModel.setGenderStr(UserGenderEnum.getDescription(resultModel.getGender()));
            //状态
            resultModel.setStatusStr(UserStatusEnum.getDescription(resultModel.getStatus()));
            //部门
            resultModel.setDepartName(userMapper.getUserDeptName(resultModel.getDepartId()));
            resultObject = ApiResultObject.success(ApiCodeEnum.SUCCESS.getCode(),"登录成功！",resultModel);
        }
        return resultObject;
    };
}
